package com.oracle.service.imp;

import org.redisson.Redisson;
import org.redisson.api.RBloomFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @program: CampusMatching
 * @description: 布隆过滤器
 * @author: zhaolei
 * @create: 2020-08-04 19:10
 **/
@Service
public class BloomFilterService {

    @Autowired
    Redisson redisson;

    public  boolean  getvalue(String news){
        RBloomFilter<String> bloomFilter =redisson.getBloomFilter("bloom");
        bloomFilter.tryInit(500000L,0.03);
        if(bloomFilter.contains(news)){
            System.out.println("在数据库中能够映射到对应的key");
            return  true;
        }else{
            System.out.println("不存在该映射");
            return  false;
        }
    }

    public  void addvalue(String news){
        RBloomFilter<String> bloomFilter =redisson.getBloomFilter("bloom");
        bloomFilter.add(news);
        System.out.println("插入到redis中");
    }

}
